<script setup lang="ts">
import { ref } from 'vue';
import { useNaiveForm } from '@/hooks/common/form';
import { $t } from '@/locales';
import DictSelect from '@/components/custom/dict-select.vue';

defineOptions({
  name: 'GameLeaderboardSearch'
});

interface Emits {
  (e: 'reset'): void;
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const { formRef, validate, restoreValidation } = useNaiveForm();


const model = defineModel<Api.Games.GameLeaderboardSearchParams>('model', { required: true });


async function reset() {
  Object.assign(model.value.params!, {});
  await restoreValidation();
  emit('reset');
}

async function search() {
  await validate();
  emit('search');
}
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse>
      <NCollapseItem :title="$t('common.search')" name="user-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
          <NGrid responsive="screen" item-responsive>
            <NFormItemGi span="24 s:12 m:6" label="用户ID" path="userId" class="pr-24px">
              <NInput v-model:value="model.userId" placeholder="请输入用户ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="游戏ID" path="gameId" class="pr-24px">
              <NInput v-model:value="model.gameId" placeholder="请输入游戏ID" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="游戏编码" path="gameCode" class="pr-24px">
              <NInput v-model:value="model.gameCode" placeholder="请输入游戏编码" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="最高分数" path="bestScore" class="pr-24px">
              <NInput v-model:value="model.bestScore" placeholder="请输入最高分数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="累计分数" path="totalScore" class="pr-24px">
              <NInput v-model:value="model.totalScore" placeholder="请输入累计分数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="游戏次数" path="playCount" class="pr-24px">
              <NInput v-model:value="model.playCount" placeholder="请输入游戏次数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="累计时长（秒）" path="totalTime" class="pr-24px">
              <NInput v-model:value="model.totalTime" placeholder="请输入累计时长（秒）" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="平均分数" path="avgScore" class="pr-24px">
              <NInput v-model:value="model.avgScore" placeholder="请输入平均分数" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="排行类型" path="rankType" class="pr-24px">
              <DictSelect v-model:value="model.rankType" dict-code="rank_type" placeholder="请选择排行类型" clearable />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="排行周期（格式：2024-01、2024-W01、2024-01-01）" path="rankPeriod" class="pr-24px">
              <NInput v-model:value="model.rankPeriod" placeholder="请输入排行周期（格式：2024-01、2024-W01、2024-01-01）" />
            </NFormItemGi>
            <NFormItemGi span="24 s:12 m:6" label="最后游戏时间" path="lastPlayTime" class="pr-24px">
              <NDatePicker
                v-model:formatted-value="model.lastPlayTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                clearable
              />
            </NFormItemGi>
            <NFormItemGi span="24" class="pr-24px">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
